package com.tma.internship.activities;

import java.io.FileInputStream;

import com.tma.internship.ClassesInfo.FileInfo;
import com.tma.internship.connectserver.ServerInfo;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class ControlFileActivity extends Activity {
	private ImageView imgView = null;
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
//		try {
//			BitmapDrawable bm = new BitmapDrawable("/data/ebook/"+fInfo.getName()+"/0.png");
//			imgView.setImageBitmap(bm.getBitmap());
//		} catch (Exception e){
//			return;
//		}
	}
	private FileInfo fInfo;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.controlfile);
		fInfo = (FileInfo) getIntent().getExtras().getSerializable("file");
		Button viewBtn = (Button) findViewById(R.id.controlview);
		Button downloadBtn = (Button) findViewById(R.id.controldownload);
		imgView = (ImageView) findViewById(R.id.controlimage);
		BitmapDrawable bm = null;
		try {
			FileInputStream fin = this.openFileInput(fInfo.getName()+"_0.png");
			bm = new BitmapDrawable(fin);
		} catch (Exception e)
		{
			e.printStackTrace();
		}
		imgView.setImageBitmap(bm.getBitmap());
		
		viewBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(getBaseContext(), ViewBookActivity.class);
				i.putExtra("file", fInfo);
				
				startActivity(i);
			}
		});
		downloadBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(ControlFileActivity.this,DownloadFileActivity.class);
				intent.putExtra("name", fInfo.getName());
				intent.putExtra("page", fInfo.getNumOfPage());
				startActivity(intent);
			}
		});
	}
	
}
